
'x=x=x=x=x=x=x=x==vonsmith==x=x=x=x=x=x=x=x=x
'In Hal v5.0 Beta the "RESPOND: YES/NO QUESTION ABOUT HAL" function should precede this.

'RESPOND: ATTRIBUTES OF HAL
'Hal attempts to respond to the user's comments about Hal.
'This is the version entirely rewritten by =vonsmith= , version 10-10-03a.
'This replaces the "RESPOND: ATTRIBUTES OF HAL" function in Ultra Hal v5.0 Beta.
'This function provides good responses to user input like:
'  Your big beautiful eyes are wonderful. I like your deep big blue pretty eyes.
'  I respect your incredible sense of urgency. Your amazing sense of high adventure is great.
'  Up to 4 adjectives before the noun and 3 after "sense of" are supported.
'The .brn files needed to run this are: Xaboutme0.brn (0 adjectives), Xaboutme1.brn (1 adj's),
'  Xaboutme2.brn (2 adj's), Xaboutme3.brn (3 adj's), Xaboutme4.brn (4 adj's),
'  Xassoc_adjective.brn (adjective list), Xassoc_MyWords.brn (noun list).
'Please note that not all words in Xassoc_adjective.brn are strictly adjectives in a technical sense.
'
If InStr(UserSentence, " MY ") > 0 Then  'Look for an occurence of "MY"
   MyWordStart = InStr(1, UserSentence, " MY ") + 4  'Move pointer to start of next word.
End If
GetResponse = HalBrain.HalFormat(GetResponse)
If MyWordStart > 0 Then  'This line allows this function to run even if a GetResponse exists.
'Enabling the next line instead of the one above makes the choice to run more restrictive.
'If Len(GetResponse) < 4 And MyWordStart > 0 Then
   Dim MyAdj(8)  'Storage for adjectives.
   'An xCount of 8 allows detection of up to 4 adjectives before the noun and an extra 3 for the "SENSE OF" case.
   'Note: Changing xCount can adversely affect the code following it.
   For xCount = 1 To 8
      If (Len(UserSentence) - MyWordStart) < 0 Then  'Is there a sentence after "MY"?
         Exit For
      Else
         'Test for special case of "MY something SENSE OF something" occurence.
         If InStr(MyWordStart, UserSentence, "SENSE OF ") = MyWordStart Then
            MyNoun = "SENSE OF "
            MyWordStart = MyWordStart + 9  'Move pointer to start of next word after "SENSE OF "
         End If
         'Get next word.
         MyWordEnd = InStr(MyWordStart, UserSentence, " ")
         If (MyWordEnd - MyWordStart) > 0 Then  'Word is at least 1 character long.
            MyWord = Mid(UserSentence, MyWordStart, (MyWordEnd - MyWordStart))  'Extract word.
            MyWordStart = MyWordEnd + 1  'Move pointer to start of next word.
         Else  'We are at the end of the UserSentence.
            Exit For
         End If
         Trim(MyWord)
         'Test if MyWord is a Noun.
         HalUserBrain = HalBrain.QABrain(MyWord, WorkingDir & "Xassoc_MyWords.brn", UserBrainRel)
         If UserBrainRel > 25 Then
'            MyNoun = MyNoun & " " & MyWord & "(" & UserBrainRel & ",Noun) "  'This line is used for testing only.
            MyNoun = MyNoun & " " & MyWord
            Trim(MyNoun)
         ElseIf MyNoun = "" Then  'Current word is not a noun.
            'Test if MyWord is an Adj
            HalUserBrain = HalBrain.QABrain(MyWord, WorkingDir & "Xassoc_adjective.brn", UserBrainRel)
            If UserBrainRel > 25 Then  'An adjective is detected.
               MyAdjCnt = MyAdjCnt + 1
'               MyAdj(MyAdjCnt) = MyWord & "(" & UserBrainRel & ",Adj) "  'This line is used for testing only.
               MyAdj(MyAdjCnt) = MyWord  'Store numbered adjectives in array when found.
               Trim(MyAdj(MyAdjCnt))
            Else  'Current word is not a recognized noun or adjective.
               Exit For
            End If
         ElseIf InStr(1, MyNoun, "SENSE OF ") > 0 Then  'Detect adjectives associated with "SENSE OF" noun.
            'Test if MyWord is an Adj
            HalUserBrain = HalBrain.QABrain(MyWord, WorkingDir & "Xassoc_adjective.brn", UserBrainRel)
            If UserBrainRel > 25 Then  'An adjective is detected.
               MyNoun = MyNoun & " " & MyWord   
            Else
               Exit For
            End If
         Else
            Exit For
         End If
      End If
   Next
End If

'Place MyNoun and MyAdj(n) (if there is one) into a selected sentence
'  and place in GetResponse.
'Select the sentence to use based on how many adjectives were detected.
If (Len(MyNoun) > 0 And MyNoun <> "SENSE OF " And MyAdjCnt > 0) Then
   'We have one or more nouns combined, and one or more adjectives in the array.
   HalAttrib = ""
   Select Case MyAdjCnt
      Case 1  'One adjective in response.
         HalAttrib = HalBrain.ChooseSentenceFromFile(WorkingDir & "Xaboutme1.brn")
         HalAttrib = Replace(HalAttrib, "<AdjResp1>", MyAdj(1), 1, -1, vbTextCompare)
      Case 2  'Two adjectives in response.
         HalAttrib = HalBrain.ChooseSentenceFromFile(WorkingDir & "Xaboutme2.brn")
         HalAttrib = Replace(HalAttrib, "<AdjResp1>", MyAdj(1), 1, -1, vbTextCompare)
         HalAttrib = Replace(HalAttrib, "<AdjResp2>", MyAdj(2), 1, -1, vbTextCompare)
      Case 3  'Three adjectives in response.
         HalAttrib = HalBrain.ChooseSentenceFromFile(WorkingDir & "Xaboutme3.brn")
         HalAttrib = Replace(HalAttrib, "<AdjResp1>", MyAdj(1), 1, -1, vbTextCompare)
         HalAttrib = Replace(HalAttrib, "<AdjResp2>", MyAdj(2), 1, -1, vbTextCompare)
         HalAttrib = Replace(HalAttrib, "<AdjResp3>", MyAdj(3), 1, -1, vbTextCompare)
      Case 4  'Four adjectives in response.
         HalAttrib = HalBrain.ChooseSentenceFromFile(WorkingDir & "Xaboutme4.brn")
         HalAttrib = Replace(HalAttrib, "<AdjResp1>", MyAdj(1), 1, -1, vbTextCompare)
         HalAttrib = Replace(HalAttrib, "<AdjResp2>", MyAdj(2), 1, -1, vbTextCompare)
         HalAttrib = Replace(HalAttrib, "<AdjResp3>", MyAdj(3), 1, -1, vbTextCompare)
         HalAttrib = Replace(HalAttrib, "<AdjResp4>", MyAdj(4), 1, -1, vbTextCompare)
   End Select
   'Place MyNoun into the selected sentence.
   HalAttrib = Replace(HalAttrib, "<MyWordResp>", MyNoun, 1, -1, vbTextCompare)
   'Might want to consider adding any existing GetResponse to this GetResponse or just this response alone?
   GetResponse = GetResponse & HalAttrib & vbCrLf  'Add this response to any existing responses.
'   GetResponse = HalAttrib & vbCrLf  'Optional: Just this response alone.
   DebugInfo = DebugInfo & "Hal has responded to a comment the user made about Hal." & vbCrLf
ElseIf Len(MyNoun) > 0 And MyNoun <> "SENSE OF " And MyAdjCnt = "" Then  'We have a noun, but no adjectives.
   'Choose a sentence that doesn't need adjectives.
   HalAttrib = HalBrain.ChooseSentenceFromFile(WorkingDir & "Xaboutme0.brn")
   HalAttrib = Replace(HalAttrib, "<MyWordResp>", MyNoun, 1, -1, vbTextCompare)
   'Might want to consider adding any existing GetResponse to this GetResponse or just this response alone?
   GetResponse = GetResponse & HalAttrib & vbCrLf  'Add this response to any existing responses.
'   GetResponse = HalAttrib & vbCrLf  'Optional: Just this response alone.
   DebugInfo = DebugInfo & "Hal has responded to a comment the user made about Hal." & vbCrLf
Else  'No noun, without a noun we can't use adjectives.
   DebugInfo = DebugInfo & "Hal cannot respond to a comment the user made about Hal." & vbCrLf
End If

'In Hal v5.0 Beta the "RESPOND: ATTRIBUTES OF USER" function should follow this.
'x=x=x=x=x=x=x=x==vonsmith==x=x=x=x=x=x=x=x=x


